/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  ZoneQunZuInfoActivity.java   
 * @Package com.jiyi.activity.zone   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-6-14 下午1:57:02   
 * @version V1.0     
 */
package com.jiyi.activity.zone;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import okhttp3.Call;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.jiyi.activity.SinglePicActivity;
import com.jiyi.bean.zone.HuoDongDetailJson;
import com.jiyi.bean.zone.QunZuInfoJson;
import com.jiyi.bean.zone.QunZuInfoJson.GroupInfo;
import com.jiyi.bean.zone.ZoneHaoYouBean;
import com.jiyi.bean.zone.ZoneHuoDongBean;
import com.jiyi.common.StringInterface;
import com.jiyi.common.VolleyRequest;
import com.jiyi.easemob.util.UserHelp;
import com.jiyi.event.QunZuListEvent;
import com.jiyi.inteface.HuoDongPopInterface;
import com.jiyi.inteface.PickPopInterface;
import com.jiyi.inteface.WebApi;
import com.jiyi.view.HuoDongPopView;
import com.jiyi.view.PickPopView;
import com.swift.base.ActivityBase;
import com.swift.base.ApplicationBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppBase;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.PermissionUtil;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;
import com.swift.maintenance.utils.ZoneHuoDongUtil;
import com.swift.utils.CameraUtils;
import com.swift.utils.DateUtils;
import com.swift.utils.DeviceUtil;
import com.swift.utils.DialogTool;
import com.swift.utils.GlideUtil;
import com.swift.widget.CircleImageView;
import com.swift.widget.TranslucentImageView;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * @ClassName: ZoneQunZuInfoActivity
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-6-14 下午1:57:02
 * 
 */
public class ZoneQunZuInfoActivity extends SinglePicActivity implements
		PickPopInterface, HuoDongPopInterface {

	@BindView(R.id.tvBack)
	TextView tvBack;
	@BindView(R.id.tvTitle)
	TextView tvTitle;
	@BindView(R.id.tvSearch)
	TextView tvSearch;

	@BindView(R.id.llMember)
	LinearLayout llMember;
	@BindView(R.id.llAllHuoDong)
	LinearLayout llAllHuoDong;
	@BindView(R.id.rlMemberAll)
	RelativeLayout rlMemberAll;
	@BindView(R.id.rlHuoDongAll)
	RelativeLayout rlHuoDongAll;

	@BindView(R.id.ivQunZuLogo)
	ImageView ivQunZuLogo;
	@BindView(R.id.tvQunZuName)
	TextView tvQunZuName;
	@BindView(R.id.tvCreator)
	TextView tvCreator;
	@BindView(R.id.tvCreateDate)
	TextView tvCreateDate;
	@BindView(R.id.tvJieShao)
	TextView tvJieShao;
	@BindView(R.id.tvMemberNum)
	TextView tvMemberNum;
	@BindView(R.id.tvHuoDongNum)
	TextView tvHuoDongNum;
	@BindView(R.id.tvMemberNumMore)
	TextView tvMemberNumMore;

	// 管理成员事件
	public final int MEMBER_MANAGE = 3;
	// 群组编辑
	public final int EDIT = 4;
	// 邀请好友事件
	public final int INVITE_FRIEND = 5;
	// 保存当前选择的id
	ArrayList<String> idsList = new ArrayList<String>();
	// 保存当前群组成员
	List<ZoneHaoYouBean> memberList = new ArrayList<ZoneHaoYouBean>();
	// 保存当前群活动
	List<ZoneHuoDongBean> huoDongList = new ArrayList<ZoneHuoDongBean>();
	// 群组ID,群主ID
	String groupId, creatorId = "";


	// 加载进度条
	Dialog dialog;

	// 活动对话框
	HuoDongPopView mHuoDongPopView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_qunzu_info);
		ButterKnife.bind(this);
		init();
	}
	
	@Override
	protected void onDestroy() {
		hideDialog(dialog);
		super.onDestroy();
	}

	private void init() {
		getIntentData();
		setTop();
		// setMember();
		getData();
		mHuoDongPopView = new HuoDongPopView(this, this);
	}

	/**
	 * @author: HYM
	 * @Title: getIntentData
	 * @Description: TODO(这里用一句话描述这个方法的作用) void
	 * @date: 2017-7-20
	 */
	private void getIntentData() {
		groupId = getIntent().getStringExtra("groupId");
	}

	/**
	 * @author: HYM
	 * @Title: getData
	 * @Description: TODO(这里用一句话描述这个方法的作用) void
	 * @date: 2017-7-20
	 */
	private void getData() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", groupId);

		VolleyRequest.StringRequestPost(this, WebApi.ZONE_GROUP_INFO, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								QunZuInfoJson temp = new Gson().fromJson(
										result, QunZuInfoJson.class);
								setGroupInfo(temp.getData());
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}
					}

					@Override
					public void stringError(VolleyError error) {
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: setMember
	 * @Description: TODO(这里用一句话描述这个方法的作用) void
	 * @date: 2017-6-14
	 */
	@SuppressLint("NewApi")
	private void setMember(final List<ZoneHaoYouBean> haoYouDatas) {
		llMember.removeAllViews();
		LinearLayout rowOne = new LinearLayout(this);
		LinearLayout rowTwo = new LinearLayout(this);
		// 得到像素密度
		float density = DeviceUtil.getInstance().getBiLi(); // 像素密度
		int width = DeviceUtil.getInstance().getScreenWidth();
		// 扣除左右边距各15
		width -= 30 * density;
		Log.d("width  ", width + "");
		// 求出最大可放的头像个数
		int maxNum = (int) Math.floor(width / (70 * density));
		if (maxNum > 0) {
			if (isCreator()) {
				/** 当前角色是创建者 **/
				// 当前成员数量(含添加按钮)小于等于 一行屏幕的最大显示数量,只显示一行成员
				if (haoYouDatas.size() + 1 <= maxNum) {
					//创建第一行
					rowOne = new LinearLayout(this);
					//设置行的布局方向
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					//设置行的内间距 左、上、右、下分别为 15、10、15、5dp
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					//遍历当前成员，用第一行的LinearLayout，添加对应的成员信息
					for (int i = 0; i < haoYouDatas.size(); i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						//行一添加一个成员信息
						rowOne.addView(getMemberItem(haoyou));
					}

					//获取创建者的邀请成员的图标View
					View invite = LayoutInflater.from(this).inflate(R.layout.item_group_member_add,null, false);
					//该图标需要跟之前的成员信息一起参与布局，同样不指定他的宽度
					LayoutParams layoutParams = new LayoutParams(
							0, LayoutParams.WRAP_CONTENT,1);
					invite.setLayoutParams(layoutParams);
					ImageView ivInvite = (ImageView) invite.findViewById(R.id.ivInvite);
					ivInvite.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							Intent intent = new Intent(
									ZoneQunZuInfoActivity.this,
									QunZuInviteActivity.class);
							idsList.clear();
							for (int i = 0; i < haoYouDatas.size(); i++) {
								idsList.add(haoYouDatas.get(i).getId());
							}
							intent.putStringArrayListExtra("had_join_friend",
									idsList);
							intent.putExtra("from", "qunzu_invite");
							intent.putExtra("groupId", groupId);
							startActivityForResult(intent, INVITE_FRIEND);
						}
					});
					//行一添加一个邀请图标View
					rowOne.addView(invite);
					//创建空的成员信息对象，补齐到maxNum的个数，如果有上下两列显示才会对齐
					for (int i = 0; i < maxNum  - haoYouDatas.size()-1; i++) {
						View view = new View(this);
						view.setLayoutParams(layoutParams);
						rowOne.addView(view);
					}
					llMember.addView(rowOne);
				} else if (haoYouDatas.size() + 1 <= maxNum * 2) {
					rowOne = new LinearLayout(this);
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = 0; i < maxNum; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowOne.addView(getMemberItem(haoyou));
					}

					rowTwo = new LinearLayout(this);
					rowTwo.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowTwo.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = maxNum; i < haoYouDatas.size(); i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowTwo.addView(getMemberItem(haoyou));
					}

					llMember.addView(rowOne);

					View invite = LayoutInflater.from(this).inflate(R.layout.item_group_member_add,null, false);
					LayoutParams layoutParams = new LayoutParams(
							0, LayoutParams.WRAP_CONTENT,1);
					invite.setLayoutParams(layoutParams);
					ImageView ivInvite = (ImageView) invite.findViewById(R.id.ivInvite);
					ivInvite.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							Intent intent = new Intent(
									ZoneQunZuInfoActivity.this,
									QunZuInviteActivity.class);
							idsList.clear();
							for (int i = 0; i < haoYouDatas.size(); i++) {
								idsList.add(haoYouDatas.get(i).getId());
							}
							intent.putStringArrayListExtra("had_join_friend",
									idsList);
							intent.putExtra("from", "qunzu_invite");
							intent.putExtra("groupId", groupId);
							startActivityForResult(intent, INVITE_FRIEND);
						}
					});
					rowTwo.addView(invite);
					
					for (int i = 0; i < maxNum * 2  - haoYouDatas.size() - 1; i++) {
						View view = new View(this);
						view.setLayoutParams(layoutParams);
						rowTwo.addView(view);
					}
					
					llMember.addView(rowTwo);
				} else {
					rowOne = new LinearLayout(this);
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = 0; i < maxNum; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowOne.addView(getMemberItem(haoyou));
					}

					rowTwo = new LinearLayout(this);
					rowTwo.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowTwo.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = maxNum; i < maxNum * 2 - 1; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowTwo.addView(getMemberItem(haoyou));
					}

					llMember.addView(rowOne);
					View invite = LayoutInflater.from(this).inflate(R.layout.item_group_member_add,null, false);
					LayoutParams layoutParams = new LayoutParams(
							0, LayoutParams.WRAP_CONTENT,1);
					invite.setLayoutParams(layoutParams);
					ImageView ivInvite = (ImageView) invite.findViewById(R.id.ivInvite);
					ivInvite.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							Intent intent = new Intent(
									ZoneQunZuInfoActivity.this,
									QunZuInviteActivity.class);
							idsList.clear();
							for (int i = 0; i < haoYouDatas.size(); i++) {
								idsList.add(haoYouDatas.get(i).getId());
							}
							intent.putStringArrayListExtra("had_join_friend",
									idsList);
							intent.putExtra("from", "qunzu_invite");
							intent.putExtra("groupId", groupId);
							startActivityForResult(intent, INVITE_FRIEND);
						}
					});
					rowTwo.addView(invite);
					llMember.addView(rowTwo);
				}

			} else {
				/** 当前角色是普通成员 **/
				// 当前成员数量小于等于 一行屏幕的最大显示数量,只显示一行成员
				if (haoYouDatas.size() <= maxNum) {
					rowOne = new LinearLayout(this);
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = 0; i < haoYouDatas.size(); i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowOne.addView(getMemberItem(haoyou));
					}
					llMember.addView(rowOne);
				}
				// 当前成员数量小于等于 两行屏幕的最大显示数量，显示两行成员
				else if (haoYouDatas.size() <= maxNum * 2) {
					rowOne = new LinearLayout(this);
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = 0; i < maxNum; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowOne.addView(getMemberItem(haoyou));
					}

					rowTwo = new LinearLayout(this);
					rowTwo.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowTwo.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = maxNum; i < haoYouDatas.size(); i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowTwo.addView(getMemberItem(haoyou));
					}
					
					for (int i = 0; i < maxNum * 2 - haoYouDatas.size(); i++) {
						View view = new View(this);
						LayoutParams layoutParams = new LayoutParams(
								0, LayoutParams.WRAP_CONTENT,1);
						view.setLayoutParams(layoutParams);
						rowTwo.addView(view);
					}

					llMember.addView(rowOne);
					llMember.addView(rowTwo);
				}
				// 当前成员数量大于 两行屏幕的最大显示数量，只截取两行成员来显示
				else {
					rowOne = new LinearLayout(this);
					rowOne.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowOne.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = 0; i < maxNum; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowOne.addView(getMemberItem(haoyou));
					}

					rowTwo = new LinearLayout(this);
					rowTwo.setLayoutDirection(LinearLayout.HORIZONTAL);
					rowTwo.setPadding((int) (15 * density),
							(int) (10 * density), (int) (15 * density),
							(int) (5 * density));
					for (int i = maxNum; i < maxNum * 2; i++) {
						final ZoneHaoYouBean haoyou = haoYouDatas.get(i);
						rowTwo.addView(getMemberItem(haoyou));
					}

					llMember.addView(rowOne);
					llMember.addView(rowTwo);
				}
			}
		}
	}

	private void setTop() {
		tvBack.setText("");
		tvTitle.setText("群资料");
		tvSearch.setVisibility(View.INVISIBLE);
	};

	@OnClick({ R.id.tvBack, R.id.tvExit, R.id.rlMemberAll, R.id.rlHuoDongAll,
			R.id.tvSearch, R.id.ivQunZuLogo, R.id.tvMemberNumMore })
	public void onClick(View view) {
		Intent intent = null;
		switch (view.getId()) {
		case R.id.tvBack:
			finish();
			break;
		case R.id.tvSearch:
			intent = new Intent(this, ZoneQunZuSettingActivity.class);
			intent.putExtra("groupId", groupId);
			intent.putExtra("groupName", tvQunZuName.getText().toString());
			intent.putExtra("groupJieShao", tvJieShao.getText().toString());
			startActivityForResult(intent, EDIT);
			break;
		case R.id.tvExit:
			// 执行退出
			DialogTool.createConfirmDialog(this, "提示", "确定退出?", "确定", "取消",
					new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							doExit();
							dialog.dismiss();
						}
					}, new DialogInterface.OnClickListener() {

						@Override
						public void onClick(DialogInterface dialog, int which) {
							dialog.dismiss();
						}
					}, DialogTool.NO_ICON).show();

			break;
		case R.id.tvMemberNumMore:
		case R.id.rlMemberAll:
			intent = new Intent(ZoneQunZuInfoActivity.this,
					MemberManageActivity.class);
			intent.putExtra("memberList", new Gson().toJson(memberList));
			intent.putExtra("creatorId", creatorId);
			intent.putExtra("groupId", groupId);
			startActivityForResult(intent, MEMBER_MANAGE);
			break;
		case R.id.rlHuoDongAll:
			intent = new Intent(ZoneQunZuInfoActivity.this,
					QunZuHuoDongActivity.class);
			intent.putExtra("groupId", groupId);
			startActivity(intent);
			break;
		case R.id.ivQunZuLogo:
			if (isCreator()) {
				mPickPopView.showPopWindow();
			}
			break;
		default:
			break;
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == CAMARE_CODE && resultCode == RESULT_OK) {
			try {
				Glide.with(this).load(new File(filePath)).into(ivQunZuLogo);
				uploadPic();
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (requestCode == CHOOSE_PICTURE) {
			if (resultCode == RESULT_OK) {
				if (data != null) {
					Uri temp = data.getData();
					filePath = CameraUtils.getImageAbsolutePath(this, temp);
					Glide.with(this).load(new File(filePath)).into(ivQunZuLogo);
					uploadPic();
				}

			}
		} else if (requestCode == MEMBER_MANAGE) {
			if (resultCode == RESULT_OK) {
				ArrayList<String> del_member = data
						.getStringArrayListExtra("del_member");

				// 从当前的成员列表删除已经删除的成员ID，然后重新填充成员列表
				if (del_member != null && del_member.size() > 0) {
					for (int i = 0; i < memberList.size(); i++) {
						for (int j = 0; j < del_member.size(); j++) {
							if (memberList.get(i).getId()
									.equals(del_member.get(j))) {
								memberList.remove(i);
								break;
							}
						}
					}
					tvMemberNum.setText("群成员(" + memberList.size() + ")");
					tvMemberNumMore.setText("查看所有群成员(" + memberList.size()
							+ ")");
					setMember(memberList);
				}
			}
		} else if (requestCode == EDIT) {
			if (resultCode == RESULT_OK) {
				tvQunZuName.setText(data.getStringExtra("qunZuName"));
				tvJieShao.setText(data.getStringExtra("jianJie"));
			}
		}
	}

	void setGroupInfo(GroupInfo groupInfo) {
		if (null != groupInfo) {
			creatorId = groupInfo.getGroup_manager_id();
			GlideUtil.load(this, groupInfo.getGroup_head(), ivQunZuLogo);
			tvQunZuName.setText(groupInfo.getName());
			tvCreator.setText(groupInfo.getGroup_manager_nickname());
			tvCreateDate.setText("本群创建于" + groupInfo.getCreate_time());
			tvJieShao.setText(groupInfo.getIntroduction());
			if (groupInfo.getMember() != null) {
				tvMemberNum
						.setText("群成员(" + groupInfo.getMember().size() + ")");
				tvMemberNumMore.setText("查看所有群成员("
						+ groupInfo.getMember().size() + ")");
				setMember(groupInfo.getMember());
				memberList = groupInfo.getMember();
			}
			if (groupInfo.getActList() != null) {
				tvHuoDongNum.setText("群活动(" + groupInfo.getActList().size()
						+ ")");
				fillAllHuoDongData(groupInfo.getActList());
			}

			if (UserInfoUtil.getCurrentUserId() == Integer.parseInt(creatorId)) {
				tvSearch.setVisibility(View.VISIBLE);
				Drawable searchDraw = getResources().getDrawable(
						R.mipmap.icon_edit);
				searchDraw.setBounds(0, 0, searchDraw.getMinimumWidth(),
						searchDraw.getMinimumHeight());
				tvSearch.setCompoundDrawables(searchDraw, null, null, null);
				tvSearch.setText("");
			}
		}
	}



	private void uploadPic() {
		if (filePath != null) {
			// 拿着imagePath上传了
			String webApi = WebApi.ZONE_GROUP_HEAD_EDIT;
			Map<String, String> params = new HashMap<String, String>();
			params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());
			params.put("id", groupId);

			PostFormBuilder postForm = OkHttpUtils.post().url(webApi);
			postForm.params(params);
			if (!TextUtils.isEmpty(filePath)) {
				File file = new File(filePath);
				postForm.addFile("group_head", "user_logo.jpg", file);
			}

			dialog = showDialog(dialog);
			postForm.build().execute(new StringCallback() {

				@Override
				public void onError(Call arg0, Exception exception, int arg2) {
					hideDialog(dialog);
					ToastUtil.getInstances().showMsg(exception.getMessage());
				}

				@Override
				public void onResponse(String result, int arg1) {
					try {
						JSONObject obj = new JSONObject(result);
						String status = obj.getString("status");
						String info = obj.getString("info");
						if (status.equals("200")) {
							ToastUtil.getInstances().showMsg(info);
						} 
						else if (status.equals("404") && info.contains("尚未登录")) {
							ToastUtil.getInstances().showMsg("尚未登录或该用户在其他地方登录，请重新登录！");
							//清除环信登录
							UserHelp.getInstance().clearUser(AppBase.Context, true);
							return;
						}
						else {
							ToastUtil.getInstances().showMsg(info);
						}
					} catch (JSONException e) {
						e.printStackTrace();
					} finally {
						hideDialog(dialog);
					}
				}
			});
		}

	}

	/**
	 * @author: HYM
	 * @Title: isCreator
	 * @Description: TODO(判断是否是创建者)
	 * @return boolean
	 * @date: 2017-7-20
	 */
	boolean isCreator() {
		return UserInfoUtil.getCurrentUserId() == Integer.parseInt(creatorId);
	}

	void doExit() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", groupId);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.ZONE_GROUP_EXIT, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								EventBus.getDefault()
										.post(new QunZuListEvent(
												QunZuListEvent.MY_QUNZU_FRAGMENT));
								EventBus.getDefault().post(
										new QunZuListEvent(
												QunZuListEvent.ALL_QUNZU_NEW));
								hideDialog(dialog);
								setResult(RESULT_OK);
								finish();
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	void fillAllHuoDongData(List<ZoneHuoDongBean> datas) {
		llAllHuoDong.removeAllViews();
		huoDongList.addAll(datas);
		for (int i = 0; i < huoDongList.size(); i++) {
			final ZoneHuoDongBean obj = huoDongList.get(i);
			View view = LayoutInflater.from(this).inflate(
					R.layout.item_zone_huodong, null, false);
			TextView tvTitle = (TextView) view.findViewById(R.id.tvTitle);
			tvTitle.setText(obj.getTheme());
			TranslucentImageView ivLogo = (TranslucentImageView) view
					.findViewById(R.id.ivHuoDongLogo);
			ivLogo.setTextString(obj.getAttendPer() + "人参与");
			GlideUtil.load(this, obj.getCover(), ivLogo);
			TextView tvAddress = (TextView) view.findViewById(R.id.tvAddress);
			tvAddress.setText(obj.getAddress());
			TextView tvStartDate = (TextView) view.findViewById(R.id.tvStartDate);
			tvStartDate.setText(DateUtils.fmtDateToStr(obj.getStart_time(), DateUtils.YMD_FORMAT));
			TextView tvEndDate = (TextView) view.findViewById(R.id.tvEndDate);
			tvEndDate.setText(DateUtils.fmtDateToStr(obj.getEnd_time(), DateUtils.YMD_FORMAT));
			TextView tvJoin = (TextView) view.findViewById(R.id.tvJoin);
			ZoneHuoDongUtil.setStatus(tvJoin, obj.getFlag());
			tvJoin.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					getHuoDongDetail(obj.getId());
				}
			});
			llAllHuoDong.addView(view);
			View spi = new View(this);
			spi.setBackgroundColor(getResources().getColor(R.color.spi_grey));
			LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 1);
			spi.setLayoutParams(params);
			llAllHuoDong.addView(spi);
		}

	}

	void getHuoDongDetail(String huoDongId) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN, UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", huoDongId);

		VolleyRequest.StringRequestPost(this, WebApi.ZONE_HUODONG_DETAIL, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								HuoDongDetailJson temp = new Gson().fromJson(
										result, HuoDongDetailJson.class);
								mHuoDongPopView.showPopWindow(temp.getData());
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}
					}

					@Override
					public void stringError(VolleyError error) {
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	@Override
	public void OnSureListener() {
		// TODO Auto-generated method stub

	}
	
	@SuppressLint("NewApi") LinearLayout getMemberItem(final ZoneHaoYouBean haoyou)
	{
		//获取成员信息的布局
		LinearLayout item = (LinearLayout) LayoutInflater.from(
				this).inflate(R.layout.item_group_member, null,
				false);
		item.setLayoutDirection(LinearLayout.VERTICAL);
		//设置成员信息View的宽度0，weight =1，成员信息就会根据不同手机的分辨率来自动设置宽度
		LayoutParams layoutParams = new LayoutParams(
				0, LayoutParams.WRAP_CONTENT,1);
		item.setLayoutParams(layoutParams);
		//设置成员信息内容水平居中
		item.setGravity(Gravity.CENTER_HORIZONTAL);
		CircleImageView memberLogo = (CircleImageView) item
				.findViewById(R.id.memberLogo);
		TextView tvMemberName = (TextView) item
				.findViewById(R.id.tvMemberName);
		GlideUtil.load(this, haoyou.getHead_path(), memberLogo);
		tvMemberName.setText(haoyou.getName());
		item.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(v.getContext(),
						PersonInfoActivity.class);
				intent.putExtra("id", haoyou.getId());
				startActivity(intent);
			}
		});
		
		return item;
	}

}
